package com.newsystem.controller;


import com.newsystem.MyUtils.CommonResult;
import com.newsystem.mapper.FollowMapper;
import com.newsystem.pojo.Follow;
import com.newsystem.service.impl.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 我的关注 前端控制器
 * </p>
 *
 * @author chenlitao
 * @since 2022-11-06
 */
@RestController
@RequestMapping("/follow")
@RequiredArgsConstructor
public class FollowController {

    private final FollowMapper followMapper;
    private final FollowService followService;

    @ApiOperation("用户关注媒体")
    @PutMapping("/addFollow")
    public CommonResult<Object> addFollow(String userId,String mediumId){
        return followService.instertFollow(userId,mediumId);
    }

    @ApiOperation("用户获取自己的关注的媒体列表")
    @GetMapping("/getFollows")
    public CommonResult<Object> getFollows(String userId){
        List<Map<String, Object>> maps = followMapper.selectByUserId(userId);
        if(maps==null){
            return CommonResult.failed("获取失败");
        }
        else {
            return CommonResult.success(maps);
        }
    }

    @ApiOperation("用户通过关注id取消关注媒体")
    @DeleteMapping("/cancel")
    public CommonResult<Object> cancelFollow(String userId,String followId){
        return followService.deleteFollow(userId,followId);
    }



}

